package com.hlz.fastnote;

import android.os.Parcel;
import android.os.Parcelable;

import org.litepal.crud.LitePalSupport;

public class Note extends LitePalSupport implements Parcelable {

    private String title;
    private String content;
    private long time;
    private long id;

    public Note(){}

    protected Note(Parcel in) {
        title = in.readString();
        content = in.readString();
        time = in.readLong();
        id = in.readLong();
    }

    public static final Creator<Note> CREATOR = new Creator<Note>() {
        @Override
        public Note createFromParcel(Parcel in) {
            return new Note(in);
        }

        @Override
        public Note[] newArray(int size) {
            return new Note[size];
        }
    };

    @Override
    public boolean save() {
        boolean s = super.save();//1先保存生成id
        setId(getBaseObjId());//2设置id
        update(getBaseObjId());//3更新数据，这样每次获取它的实例就能保证正确获取id了。
        return s;
    }

    @Override
    protected long getBaseObjId() {
        return super.getBaseObjId();
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }


    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(title);
        parcel.writeString(content);
        parcel.writeLong(time);
        parcel.writeLong(id);
    }
}
